import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/data/store/config_store.dart';
import 'package:bxultimate/resources/assets.dart';
import 'package:bxultimate/widgets/app/app_title.dart';
import 'package:bxultimate/widgets/mk_cell.dart';
import 'package:bxultimate/widgets/mk_load_image.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:bxultimate/widgets/mk_scroll_view.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class UserCompleteInformationPage extends StatefulWidget {
  const UserCompleteInformationPage({Key? key}) : super(key: key);

  @override
  State<UserCompleteInformationPage> createState() =>
      _UserCompleteInformationPageState();
}

class _UserCompleteInformationPageState
    extends State<UserCompleteInformationPage> {
  final controller = Get.find<UserCompleteInformationController>();
  final state = Get.find<UserCompleteInformationController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: TDNavBar(
          backgroundColor: Colors.transparent,
          title: '完善信息',
        ),
        body: MkScrollView(
          bottomButton: TDButton(
            text: '保存',
            shape: TDButtonShape.circle,
            height: 48,
            onTap: controller.save,
            isBlock: true,
            theme: TDButtonTheme.primary,
          ),
          children: [
            Gaps.vGap16,
            Padding(
                padding: EdgeInsets.only(left: AppTheme.iDefaultPadding),
                child: AppTitle(title: '基本信息')),
            Gaps.vGap16,
            TDInput(
              controller: controller.nameController,
              leftLabel: '姓名',
              required: true,
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            TDInput(
              controller: controller.idcardController,
              leftLabel: '身份证号',
              required: true,
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            Obx(() => TDCell(
                  style: TDCellStyle(
                      backgroundColor: Colors.transparent,
                      requiredStyle: TextStyle(
                        color: TDTheme.of(context).errorColor6,
                        fontSize: TDTheme.of(context).fontBodyLarge?.size ?? 16,
                        height: TDTheme.of(context).fontBodyLarge?.height ?? 24,
                        fontWeight: FontWeight.w400,
                      )),
                  arrow: true,
                  required: true,
                  noteWidget: _noteWidget("${state.information.birthday}"),
                  title: '生日',
                  onClick: controller.showBirthdayPicker,
                )),
            Obx(() => MkCell(
                  arrow: true,
                  noteWidget: _noteWidget(controller.getDictLabel("sex")),
                  title: '性别',
                  onClick: () {
                    controller.showPicker("sex");
                  },
                )),
            Obx(() => MkCell(
                  arrow: true,
                  noteWidget: _noteWidget(controller.getDictLabel("nation")),
                  title: '民族',
                  onClick: () {
                    controller.showPicker("nation");
                  },
                )),
            Obx(() => MkCell(
                  arrow: true,
                  noteWidget:
                      _noteWidget(controller.getDictLabel("politics_status")),
                  title: '政治面貌',
                  onClick: () {
                    controller.showPicker("politics_status");
                  },
                )),
            TDInput(
              controller: controller.phoneController,
              leftLabel: '联系方式',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            Obx(() => MkCell(
                  arrow: true,
                  noteWidget: _noteWidget(controller.getDictLabel("education")),
                  title: '学历',
                  onClick: () {
                    controller.showPicker("education");
                  },
                )),
            Obx(() => MkCell(
                  arrow: true,
                  noteWidget: state.information.address != ''
                      ? _noteWidget('')
                      : _noteWidget('请选择地理位置'),
                  description: state.information.address,
                  title: '家庭住址',
                  onClick: controller.addressSelect,
                )),
            Obx(() => state.information.jgText == null
                ? SizedBox()
                : MkCell(
                    arrow: true,
                    noteWidget: _noteWidget(state.information.jgText),
                    title: '籍贯',
                    onClick: () {
                      controller.showJgPicker();
                    },
                  )),
            Obx(() => MkCell(
                  arrow: true,
                  noteWidget:
                      _noteWidget(controller.getDictLabel("native_type")),
                  title: '户籍类别',
                  onClick: () {
                    controller.showPicker("native_type");
                  },
                )),
            Obx(() => state.information.hjszdText == null
                ? SizedBox()
                : MkCell(
                    arrow: true,
                    noteWidget: _noteWidget(state.information.hjszdText),
                    title: '户籍所在地',
                    onClick: () {
                      controller.showHjszdPicker();
                    },
                  )),
            Obx(() => state.information.photo == null
                ? SizedBox()
                : MkCell(
                    arrow: true,
                    noteWidget: Container(
                      width: 80,
                      height: 120,
                      child: MkLoadImage(ConfigStore.to.baseFileUrl +
                          state.information.photo!),
                    ),
                    title: '个人一寸照',
                    onClick: () {
                      controller.showPicPicker();
                    },
                  )),
            Gaps.vGap16,
            Padding(
                padding: EdgeInsets.only(left: AppTheme.iDefaultPadding),
                child: AppTitle(title: '健康信息')),
            Gaps.vGap16,
            TDInput(
              controller: controller.heightController,
              leftLabel: '身高',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            TDInput(
              controller: controller.weightController,
              leftLabel: '体重',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            TDInput(
              controller: controller.visionLeftController,
              leftLabel: '左眼视力',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            TDInput(
              controller: controller.visionRightController,
              leftLabel: '右眼视力',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            Gaps.vGap16,
            Padding(
                padding: EdgeInsets.only(left: AppTheme.iDefaultPadding),
                child: AppTitle(title: '其他信息')),
            Gaps.vGap16,
            TDInput(
              controller: controller.formerNameController,
              leftLabel: '曾用名',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            Obx(() => MkCell(
                  arrow: true,
                  noteWidget: _noteWidget(controller.getDictLabel("religion")),
                  title: '宗教信仰',
                  onClick: () {
                    controller.showPicker("religion");
                  },
                )),
            Obx(()=>MkCell(
              arrow: true,
              noteWidget: _noteWidget(controller.getDictLabel("isOnlychild")),
              title: '独生子女',
              onClick: () {
                controller.showPicker("isOnlychild");
              },
            )),
            Obx(()=>MkCell(
              arrow: true,
              noteWidget:
              _noteWidget(controller.getDictLabel("marriageStatus")),
              title: '婚姻状况',
              onClick: () {
                controller.showPicker("marriageStatus");
              },
            )),
            Obx(() => MkCell(
                  arrow: true,
                  noteWidget: _noteWidget(controller.getDictLabel("cylb")),
                  title: '从业类别',
                  onClick: () {
                    controller.showPicker("cylb");
                  },
                )),
            TDInput(
              controller: controller.unitNameController,
              leftLabel: '单位名称',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
          ],
        ),
      ),
    );
  }

  _noteWidget(text) {
    return Text(
      text,
      style: TextStyle(fontSize: 16),
    );
  }

  @override
  void dispose() {
    Get.delete<UserCompleteInformationController>();
    super.dispose();
  }
}
